package com.mdhw.controller;

import com.mdhw.config.R;
import com.mdhw.system.vo.SysUserVo;
import com.mdhw.user.service.MiliUserService;
import com.mdhw.user.vo.MiliUserVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@Api(tags = "用户")
@RequestMapping("miliUser")
public class MiliUserController {

    @Autowired
    private MiliUserService miliUserService;


//    @PostMapping("/login")
//    @ApiOperation(value = "登录")
//    public R<SysUserVo> login(@RequestBody @Validated MiliUserVo sysUser) {
//        String code = sysUser.getCode();
//        String type = sysUser.getType();
//        if(StringUtils.isNotBlank(type) && "2".equals(type) && StringUtils.isNotBlank(code)){
//
//            R<String> checkResult = this.miliUserService.checkCode(sysUser.getPhone(), sysUser.getCode(), sysUser.getType());
//            if(checkResult.getCode() != 0){
//                return R.error(checkResult.getMsg());
//            }
//            return this.miliUserService.authPwdByCode(sysUser);
//
//        }
//        return this.miliUserService.authPwd(sysUser);
//    }


    @GetMapping("/selectUserByToken")
    @ApiOperation(value = "获取用户详情通过 token")
    public R<MiliUserVo> selectUserByToken(){
        MiliUserVo sysUserVo = this.miliUserService.selectUserByToken();
        if(sysUserVo != null){
            sysUserVo.setPassword(null);
            sysUserVo.setSalt(null);
        }

        return R.success(sysUserVo);
    }
}
